// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets;

import java.nio.ByteBuffer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;
import zombie.radio.ZomboidRadio;

public class WaveSignal implements INetworkPacket {
    int sourceX;
    int sourceY;
    int channel;
    String msg;
    String guid;
    String codes;
    float r;
    float g;
    float b;
    int signalStrength;
    boolean isTV;

    public void set(
        int _sourceX, int _sourceY, int _channel, String _msg, String _guid, String _codes, float _r, float _g, float _b, int _signalStrength, boolean _isTV
    ) {
        this.sourceX = _sourceX;
        this.sourceY = _sourceY;
        this.channel = _channel;
        this.msg = _msg;
        this.guid = _guid;
        this.codes = _codes;
        this.r = _r;
        this.g = _g;
        this.b = _b;
        this.signalStrength = _signalStrength;
        this.isTV = _isTV;
    }

    @Override
    public void parse(ByteBuffer _b, UdpConnection connection) {
        this.sourceX = _b.getInt();
        this.sourceY = _b.getInt();
        this.channel = _b.getInt();
        this.msg = null;
        if (_b.get() == 1) {
            this.msg = zombie.GameWindow.ReadString(_b);
        }

        this.guid = null;
        if (_b.get() == 1) {
            this.guid = zombie.GameWindow.ReadString(_b);
        }

        this.codes = null;
        if (_b.get() == 1) {
            this.codes = zombie.GameWindow.ReadString(_b);
        }

        this.r = _b.getFloat();
        this.g = _b.getFloat();
        this.b = _b.getFloat();
        this.signalStrength = _b.getInt();
        this.isTV = _b.get() == 1;
    }

    @Override
    public void write(ByteBufferWriter _b) {
        _b.putInt(this.sourceX);
        _b.putInt(this.sourceY);
        _b.putInt(this.channel);
        _b.putBoolean(this.msg != null);
        if (this.msg != null) {
            _b.putUTF(this.msg);
        }

        _b.putBoolean(this.guid != null);
        if (this.guid != null) {
            _b.putUTF(this.guid);
        }

        _b.putBoolean(this.codes != null);
        if (this.codes != null) {
            _b.putUTF(this.codes);
        }

        _b.putFloat(this.r);
        _b.putFloat(this.g);
        _b.putFloat(this.b);
        _b.putInt(this.signalStrength);
        _b.putBoolean(this.isTV);
    }

    public void process(UdpConnection connection) {
        if (GameServer.bServer) {
            ZomboidRadio.getInstance()
                .SendTransmission(
                    connection.getConnectedGUID(),
                    this.sourceX,
                    this.sourceY,
                    this.channel,
                    this.msg,
                    this.guid,
                    this.codes,
                    this.r,
                    this.g,
                    this.b,
                    this.signalStrength,
                    this.isTV
                );
        } else {
            ZomboidRadio.getInstance()
                .ReceiveTransmission(
                    this.sourceX, this.sourceY, this.channel, this.msg, this.guid, this.codes, this.r, this.g, this.b, this.signalStrength, this.isTV
                );
        }
    }
}
